home *** CD-ROM | disk | FTP | other *** search
/ CICA 1993 April / CICA MS Windows - April 1993.iso / unzipped / programr / listings / ptv2n5 / wrdcount.pas < prev   
Pascal/Delphi Source File  |  1991-09-18  |  2KB  |  100 lines

  1. Library WrdCount;
  2.  
  3. USES
  4.   WinDos,
  5.   WinCrt,
  6.   AsmCoun1;
  7.  
  8. VAR
  9.   SaveExit      : pointer;          { exit proc variable }
  10.   FileName      : string;
  11.   FileExtension : string [3];
  12.   Counter       : CountPtr;
  13.  
  14. { LibExit =============================================== }
  15.  
  16. {$S-}
  17. PROCEDURE LibExit ; far;
  18. begin
  19.   ExitProc := SaveExit;
  20. end;
  21.  
  22. { TimeMs ================================================ }
  23.  
  24. function TimeMs : LongInt;
  25. { Returns time of day in milliseconds since midnight }
  26.  
  27. var Regs : Tregisters;
  28.  
  29. begin
  30.   with Regs do begin
  31.     AH := $2C;
  32.     DS := Dseg;                                  { Windows demands this! }
  33.     ES := Dseg;                                  { ditto }
  34.     MsDos(Regs);
  35.     TimeMs := 1000*(LongInt(DH)
  36.       +60*(LongInt(CL)
  37.         +60*LongInt(CH)))
  38.           +10*LongInt(DL);
  39.   end;
  40. end;
  41.  
  42. { FileExists ============================================ }
  43.  
  44. function FileExists (FileName: String) : Boolean; export;
  45. { Boolean function that returns True if the file exists;otherwise,
  46.    it returns False. Closes the file if it exists. }
  47.  
  48. var F : file;
  49.  
  50. begin
  51.   {$I-}
  52.   Assign(F, FileName);
  53.   Reset(F);
  54.   Close(F);
  55.   {$I+}
  56.   FileExists := (IOResult = 0) and (FileName <> '');
  57. end;  { FileExists }
  58.  
  59. { CountFile ============================================= }
  60.  
  61. PROCEDURE CountFile (FileName : string;
  62.                      VAR Start, Stop, FinalCount : longint); export;
  63.  
  64. var loop : byte;
  65.  
  66. begin
  67. { get the file extension }
  68.     loop := pos ('.', FileName);
  69.     if loop = 0 then FileExtension := ''
  70.       else FileExtension := copy (FileName, succ (loop), 3);
  71.  
  72. { Initialize the Count object. }
  73.   if FileExtension = 'SAM' then
  74.     Counter := New (AmiCountPtr, Init (FileName))
  75.   else
  76.        if FileExtension = 'SPR' then
  77.         Counter := New (SprintCountPtr, Init (FileName))
  78.       else
  79.            Counter := New (CountPtr, Init (FileName));
  80.  
  81. { Count, store, exit. }
  82.   With Counter^ do begin
  83.          Start := TimeMs;
  84.       Count;
  85.       Stop := TimeMs;
  86.     FinalCount := WordCount;
  87.          end;
  88.   Dispose (Counter, Done);
  89. end;
  90.  
  91. { ======================================================= }
  92. EXPORTS
  93.   FileExists index 1,
  94.   CountFile index 2;
  95.  
  96. BEGIN
  97.   SaveExit := ExitProc;    { save old exit proc pointer }
  98.   ExitProc := @LibExit;    { install LibExit proc }
  99. END.
  100.